<?php
namespace Home\Controller;
use Think\Controller;
/**
 * 父类控制器，需要继承
 * @file ParentController.class.php
 * @author Gary <lizhiyong2204@sina.com>
 * @date 2015年8月4日
 * @todu
 */
class ParentController extends Controller {

    public function __construct(){
//        echo 111;die;
        parent::__construct();
        //通过session_id取得用户的授权信息
        //且通过open_id_pre判断授权信息是否是当前平台的数据
        $domain = $_SERVER['HTTP_HOST'];//绑定域名
        //dump($_SERVER['HTTP_HOST']);die;
        $rs = D('platform')->field('open_id_pre')->where("domain='{$domain}'")->find();
        $map['open_id_pre'] = $rs['open_id_pre'];
        $map['session_id'] = session_id();
        $session_count = D('session')->where($map)->count();
        //echo $session_count;die;
        if(!empty($session_count)){ //匹配成功
            //直接跳转到落地域名
            $d_map['set_domain'] = $_SERVER['HTTP_HOST'];
            $d_map['status'] = '0';
            //dump($d_map);die;
            $d_info = D('domain')->field('show_domain')->where($d_map)->find();
            //dump($d_info);die;
            $url = 'http://'.$d_info['show_domain'].$_SERVER['REQUEST_URI'];
            //dump($url);die;
            header("Location: $url");
            die;
        }else{ //匹配不成功，跳转认证
            //echo 111;die;
            //dump($_SERVER['HTTP_HOST']);die;
            
            $url = 'http://'.$_SERVER['HTTP_HOST'].'/Identify/identify?redirect='.$_SERVER['REQUEST_URI'];
//            dump($url);die;
            header("Location: $url");
            die;
        }



    }
}